package com.wondersgroup.fjzlpt.console.service.impl.yljgxx;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.quick.framework.boot.remoteResult.ResultObject;
import com.wondersgroup.fjzlpt.console.dao.inter.yljgxx.YljgZyjrDAO;
import com.wondersgroup.fjzlpt.console.service.inter.yljgxx.YljgZyjrService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * 医疗机构资源接入信息
 * Created by lion on 2017/8/8.
 */
@Service
public class YljgZyjrServiceImpl implements YljgZyjrService {

    @Autowired
    private YljgZyjrDAO yljgZyjrDAO;

    @Override
    public JSONObject save(Map map) {
        ResultObject ro = new ResultObject();
        try{
            String PTJGID = (String)map.get("PTJGID");
            deleteByPtjgid(PTJGID);
            String zyjrxx = (String)map.get("zyjrxx");
            JSONArray ary = JSON.parseArray(zyjrxx);
            yljgZyjrDAO.insertBatch(ary.toJavaList(Map.class));
        }catch (Exception e){
            e.printStackTrace();
            ro.changeFaultState("保存接入资源配置失败");
            throw new RuntimeException("保存接入资源配置失败", e);
        }

        return (JSONObject)JSON.toJSON(ro);
    }

    /**
     * 查询机构资源接入信息
     * @param map
     * @return
     */
    public JSONArray queryZyjrxx(Map map){
        String PTJGID = (String)map.get("PTJGID");
        return yljgZyjrDAO.queryByPtjgid(PTJGID);
    }

    /**
     * 删除配置
     * @param ptjgid
     */
    private void deleteByPtjgid(String ptjgid){
        yljgZyjrDAO.deleteByPtjgid(ptjgid);
    }
}













